package com.susu.zookeeper.curator.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author 苏苏
 */
@Slf4j
@Configuration
public class AppConfig {

    @Value("${credit.zk.address}")
    private String zkServerUrl;

    @Bean
    public CuratorFramework curatorFramework() {
        CuratorFramework curatorFramework = CuratorFrameworkFactory.newClient(zkServerUrl,
                new ExponentialBackoffRetry(100, 3));
        log.info("init curatorFramework...");
        curatorFramework.start();
        return curatorFramework;
    }
}
